<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <script type="text/javascript" src="../../inc/ctx.jsp"></script>
        <script type="text/javascript" src="../js/g.js"></script>
        <script type="text/javascript" src="../js/channeltype.js"></script>
        <link href="../css/com.css" type="text/css" rel="stylesheet"/>
        <style>
            img.s1{width:100px;border:1px #EFEFEF solid;padding:1px;}
            #datalist tr td{text-align:center;}
        </style>
    </head>
    <body>
        <div id="panel">
            <form id="queryFrm">
                <input name="rownum" id="rownum" value="" type="hidden" />
                <input name="crow" id="crow" value="" type="hidden" />
                <input name="currpage" id="currpage" value="" type="hidden" />
                <table border="0" cellspacing="0" cellpadding="0">
                    <tr class="trhd">
                        <td colspan="2"><h3 class="s1">链接管理</h3></td>
                        <td width="8%">&nbsp;</td>
                        <td width="24%">&nbsp;</td>
                        <td width="6%">&nbsp;</td>
                        <td width="37%">&nbsp;</td>
                    </tr>
                    <tr>
                        <td height="28" class="r">发布状态： </td>
                        <td><select id="pubstate" name="pubstate" style="width:100px;">
                                <option value=""></option>
                                <option value="1">1-是-</option>
                                <option value="0">0-否-</option>
                            </select>
                            <span class="r">
                                <input onClick="LINK.updatePubState();" type="button" id="updateBtn1" value="更新">
                            </span></td>
                        <td class="r">信息类别： </td>
                        <td><input type="hidden" name="cid" id="cid" value=""/>
                            ctp:
                            <input type="text" name="ctp" id="ctp" value="" style="width:50px;" readonly="readonly"  onClick="selectCatelogs();"/>
                            <input type="button" value="清空" onClick="$('#cid').val('');$('#ctp').val('');"/>
                            <input onClick="LINK.updateCatalog();" type="button" id="updateBtn3" value="更新类别"></td>
                        <td class="r">站名搜索： </td>
                        <td><input id="title" name="title" value="" maxlength="20" style="width:120px;" onClick="this.value=''"/></td>
                    </tr>
                    <tr>
                        <td class="r">权重范围：</td>
                        <td>从 <input type="text" id="beginWeight" name="beginWeight" value=""  style="width:50px;"/>到
                            <input type="text" id="endWeight" name="endWeight" value=""  style="width:50px;"/></td>
                        <td class="r">所属板块：</td>
                        <td><script>out_select('channeltype');</script></td>
                        <td class="r">每页显示：</td>
                        <td><select name="listsize" id="listsize">
                                <option value="20">20条</option>
                                <option value="50">50条</option>
                            </select>
                            &nbsp;</td>
                    </tr>
                    <tr>
                        <td class="r">链接ID：</td>
                        <td><input type="text" id="lkid" name="lkid" value="" maxlength="8" onClick="this.value='';"/></td>
                        <td class="r">创建时间：</td>
                        <td> 从 <input type="text" id="createBeginDate" name="createBeginDate" value="" maxlength="19" style="width:100px;" onclick="cdpn('createBeginDate');"/>
                            到 <input type="text" id="createEndDate" name="createEndDate" value="" maxlength="19" style="width:100px;"  onclick="cdpn('createEndDate');"/>
                        </td>
                        <td>&nbsp;</td>
                        <td><span id="tip_num"></span></td>
                    </tr>
                    <tr>
                        <td width="7%" class="r">链接类型：</td>
                        <td width="18%">
                            <select id="lktype" name="lktype" style="width:100px;">
                                <option value="">-选择-</option>
                                <script type="text/javascript" src="../js/linkcfg.js"></script>
                            </select>
                        </td>
                        <td class="r">&nbsp;</td>
                        <td>&nbsp;</td>
                        <td></td>
                        <td><input onclick="LINK.list(1, 0);" name="submitBtn" type="button" class="button small orange" id="submitBtn" value="Φ 查询">
                            <input onClick="LINK.del();" type="button" class="button small gray" id="delBtn" value="x 删除">
                        </td>
                    </tr>
                </table>
            </form>
        </div>


        <div class="databox">
            <table border="0" cellspacing="0" cellpadding="0">
                <tr>
                    <th width="3%"><a href="javascript:ut.swapsel('sel');">反选</a></th>
                    <th width="3%">ID</th>
                    <th width="13%">链接名称</th>
                    <th width="10%">链接图片</th>
                    <th width="13%">创建时间</th>
                    <th width="17%">链接地址</th>
                    <th width="10%">链接类型</th>
                    <th width="6%">权重</th>
                    <th width="6%">发布状态</th>
                    <th width="8%">CID/CTP</th>
                    <th width="11%">操作</th>
                </tr>
                <tbody class="tbchg" id="datalist"></tbody>
            </table>
        </div>
        <div class="page" id="page"></div>

        <div style="display:block;clear:both;width:98%;height:50px;">&nbsp;</div>





<!-- 数据处理 -->
<script id="listTpl" type="text/html">
            {%  for(var k in list){ var e = list[k]; %}
        <tr>
            <td><input name="sel" type="checkbox" value="{%=e.lkid%}"/></td>
            <td>{%=e.lkid%}</td>
            <td><a href="{%=e.siteurl%}" target="_blank">{%=e.title%}</a></td>
            <td>
                {% if(e.logopic.length>9){ %}
                <span class="img1"><img src="{%=e.logopic%}" class="s1"/></span>
                {% }else{ %}
                暂无图片.
                {% } %}
            </td>
            <td>{%=formatTime(e.createtime)%}</td>
            <td><input value="{%=e.siteurl%}" id="siteurl{%=e.lkid%}" type="text" size="20"/></td>
            <td>{%=out_type(e.lktype)%}</td>
            <td><input value="{%=e.weight%}" id="weight{%=e.lkid%}" type="text" size="10" maxlength="7" onchange="LINK.updateWeight('{%=e.lkid%}', this.value);"/></td>
            <td>{%=getPubState(e.pubstate)%}</td>
            <td>{%=e.cid%}<br/>{%=e.ctp%}</td>
            <td>
                <a  href="#edit" onclick="LINK.edit('{%=e.lkid%}');">编辑</a> 
            </td>
        </tr>
        {% } %}
</script>

    <script type="text/javascript">
        var $lsout = $('#datalist');
        var $ls = $('#listsize');
        var $rownum = $('#rownum');
        var $crow=$('#crow');
        var $curpage=$('#currpage');
        var LINK={
            list:function(pgno,r){
                var ls = parseInt($ls.val());
                var step =10;
                var cr = (ls * ( pgno - 1 ));
                $rownum.val(r);
                $crow.val(cr);
                $curpage.val(pgno);
                var params = ut.getFormData('#queryFrm');
                params._t=ut.r();
                $.get('../app/link/list_factor.shtm',params,function(d){
                    var x = d;
                    rn=x.rownum;
                    $('#tip_num').text('查到 '+rn+' 条信息');
                    $rownum.val(rn);
                    if(rn>0){
                        ut.outpage(pgno, rn, 'LINK.list','page', ls, step);
                        $lsout.html(template.render('listTpl',x));
                    }else{
                        $lsout.html('<tr><td colspan="6">暂无数据.</td></tr>');
                        $('#page').html('');
                    }
                }
            );
            },
            del:function(){
                var ida = ut.getselv('sel');
                if(va.isnull(ida)){ut.m('请选择需要删除的信息.');return;}
                if(!window.confirm("确定删除么?执行后不可恢复."))return;
                $.get('../app/link/delete_batch.shtm?t='+ut.r(), "ids="+ida, function(x){
                    var r = $.trim(x);
                    if(va.tint(r)){
                        ut.m('删除成功.已删除记录数为'+r);
                        LINK.list($curpage.val(),0);
                    }else{
                        ut.m('删除失败. '+r);
                    }
                });
            },
            updatePubState:function(){
                var ida = ut.getselv('sel');
                if(va.isnull(ida)){ut.m('请选择需要更新的信息.');return;}
                var st = $('#pubstate').val();
                if(va.isnull(st)){ut.m('请选择发布状态.');return;}
                var p = {'ids':ida,'pubstate':st};
                $.get('../app/link/update_pubstate.shtm',$.param(p), function(x){
                    var r = $.trim(x);
                    if(va.tint(r)){
                        ut.m('更新成功.已更新记录数为'+r);
                        LINK.list($curpage.val(),0);
                    }else{
                        ut.m('更新失败. '+r);
                    }
                });
            },
            updateWeight:function(id,w){
                if(!va.isint(w) || w<=0){return;}
                var p={'lkid':id,'weight':w};
                $.get('../app/link/update_weight.shtm',$.param(p), function(x){
                    var r = $.trim(x);
                    if(va.tint(r)){
                        TxBox.wait('更新成功！');
                        LINK.list($curpage.val(),$rownum.val());
                    }else{
                        TxBox.wait('更新失败！');
                    }
                    TxBox.hide();
                });
            },
            updateCatalog:function(){
                var ida = ut.getselv('sel');
                if(va.isnull(ida)){ut.m('请选择需要更新的信息.');return;}
                var ct = $('#channeltype').val();
                var cid = $('#cid').val();
                var ctp = $('#ctp').val();
                if(!va.mint(ct) || !va.isint(cid)){ut.m('请选择类别.');return;}
                var p = {'ids':ida, 'cid':cid, 'ctp':ctp, 'channeltype':ct};
                $.get('../app/link/update_catelog.shtm',$.param(p), function(x){
                    var r = $.trim(x);
                    if(va.tint(r)){
                        ut.m('更新成功.已更新记录数为'+r);
                        LINK.list($curpage.val(),0);
                    }else{
                        ut.m('更新失败. '+r);
                    }
                });   
            },
            edit:function(id){
                win.open('links_edit.html?lkid='+id+'&t='+ut.r());
            }
        };
            

        function formatTime(t){
            if(t>1000){
                return ut.parseDate(t,16);
            }
            return '-';
        };
            
        function selectCatelogs(){
            var ct = $('#channeltype').val();
            if(!va.mint(ct)){
                TxBox.alert('请先选择板块.');
                return;
            }
            TxBox.winpop(250,350,'类目选择', 'catalogs_select_pop.html?channeltype='+ct);
        };
            
        function reloadCatData(cid,ctp){
            $('#cid').val(cid);
            $('#ctp').val(ctp);
            $('#ctp_name_path').text(cid+';'+ctp);
            TxBox.closeWinpop();
        };
            
        template.helper('formatTime',formatTime);
        template.helper('out_type',out_type);
        template.helper('getPubState',getPubState);
        
        jQuery(function(){
            $('#channeltype').val('4').attr('readonly','readonly');
            $('#channeltype').change(function(){
                $('#cid').val('');
                $('#ctp').val('');
                if($('#channeltype').val()!='4'){
                    $('#channeltype').val('4');
                }
            });
        });
    </script>
</body>
</html>
